using System;
using Microsoft.SmallBasic.Library;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SmallBasicFun.Tests.HomeworkTests
{
	[TestClass]
	public class HomeworkForHousesTest
	{
		private static Primitive ___ = "Fill in the blank ___";

		private static readonly Primitive equals = "=";
		private static int answerUntil;
		private static int answersTried;
		private static Primitive numberOfHarryPotterBooks;
		private static Primitive xmasList;
		private static Primitive bedPost;
		private static Primitive thingsThatSmellFunny;
		private static Primitive heigth;

		[TestMethod]
		public void TestQuiz()
		{
			SetQuestionsToAnswer(19);
			Homework.LastQuestionAnsweredCorrectly = () => 0;
			Homework.StartHousesHomeworkAt += youcanreadvariables;
			ApprovalHelper.ApproveProgramWindow();
		}

		private void SetQuestionsToAnswer(int until)
		{
			answerUntil = until;
			answersTried = 0;
		}


		private static Primitive getAnswer(Primitive ifTrying)
		{
			return getAnswer(ifTrying, ___);
		}

		private static T getAnswer<T>(T ifTrying, T theBlank)
		{
			var ans = answerUntil > answersTried ? ifTrying : theBlank;
			answersTried++;
			return ans;
		}


		private static void youcanreadvariables()
		{
			var numberOfDesserts = 5;
			Homework.CheckAnswer(getAnswer(5), equals, numberOfDesserts);
		}

		private static void youcansavevariables()
		{
			var ickynessOfBrothers = getAnswer(10);
			Homework.CheckAnswer(10, equals, ickynessOfBrothers);
		}

		private static void youcandomathwithvariables()
		{
			___ = 3 + 4;
			Homework.CheckAnswer(7, equals, getAnswer(___, numberOfHarryPotterBooks));
		}

		private static void youcanchangevariables()
		{
			var milkTastiness = 6;
			addChocolate();
			milkTastiness = 10;
			Homework.CheckAnswer(getAnswer(10), equals, milkTastiness);
		}

		private static void addChocolate()
		{
		}


		private static void variablesaresnotstuck()
		{
			var boogers = 4;
			blowNose();
			boogers = getAnswer(0);
			Homework.CheckAnswer(0, equals, boogers);
		}

		private static void blowNose()
		{
		}

		private static void youcanaddtoavariable()
		{
			var age = 11;
			celebrateBirthday();
			age = age + getAnswer(1);
			Homework.CheckAnswer(12, equals, age);
		}

		private static void celebrateBirthday()
		{
		}

		private static void youcansubtractfromavariable()
		{
			var amountOfHomework = 3;
			amountOfHomework = amountOfHomework - getAnswer(3);
			Homework.CheckAnswer(0, equals, amountOfHomework);
		}

		private static void youcanmultiplyvariables()
		{
			var volumeOfMyVoice = 2;
			var volumeMyMomHears = volumeOfMyVoice*5;
			Homework.CheckAnswer(getAnswer(10), equals, volumeMyMomHears);
		}

		private static void youcandividevariables()
		{
			var inches = 36;
			var feet = getAnswer(inches)/12;
			Homework.CheckAnswer(3, equals, feet);
		}

		private static void youcansetvariablesinothermethods()
		{
			CreateXmasList();
			Homework.CheckAnswer(getAnswer("hippopotamus"), equals, xmasList);
		}

		private static void CreateXmasList()
		{
			xmasList = "hippopotamus";
		}

		private static void youcancallmethodsbyname()
		{
			getAnswer<Action>(PrepareForBed, ______)();
			Homework.CheckAnswer("gum", equals, bedPost);
		}

		private static void PrepareForBed()
		{
			bedPost = "gum";
		}

		private static void youcanchoosethemethodnames()
		{
			getAnswer<Action>(_____, ______)();
			Homework.CheckAnswer("feet", equals, thingsThatSmellFunny);
			// You need to change two blanks for this problem
		}

		private static void _____()
		{
			thingsThatSmellFunny = "feet";
		}

		private static Action ______ = () => { };

		private static void changingvariableinothermethods()
		{
			heigth = 4;
			Grow();
			Homework.CheckAnswer(5, equals, heigth);
		}

		private static void Grow()
		{
			heigth = heigth + getAnswer(1);
		}
	}
}